package com.ruoyi.business.controller;

import java.util.List;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.AppTaskOrder;
import com.ruoyi.business.service.IAppTaskOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务订单Controller
 * 
 * @author CuiYingJie
 * @date 2020-12-03
 */
@RestController
@RequestMapping("/business/order")
public class AppTaskOrderController extends BaseController
{
    @Autowired
    private IAppTaskOrderService appTaskOrderService;

    /**
     * 查询任务订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppTaskOrder appTaskOrder)
    {
        startPage();
        List<AppTaskOrder> list = appTaskOrderService.selectAppTaskOrderList(appTaskOrder);
        return getDataTable(list);
    }

    /**
     * 导出任务订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:order:export')")
    @Log(title = "任务订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppTaskOrder appTaskOrder)
    {
        List<AppTaskOrder> list = appTaskOrderService.selectAppTaskOrderList(appTaskOrder);
        ExcelUtil<AppTaskOrder> util = new ExcelUtil<AppTaskOrder>(AppTaskOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取任务订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appTaskOrderService.selectAppTaskOrderById(id));
    }

    /**
     * 管理员审核任务订单
     */
    @Log(title = "任务订单", businessType = BusinessType.UPDATE)
    @PutMapping("/checkTaskOrder")
    public AjaxResult checkTaskOrder(@RequestBody Map<String, String> data){
        return toAjax(appTaskOrderService.checkTaskOrder(data));
    }

    /**
     * 撤回已审核成功订单
     */
    @Log(title = "任务订单", businessType = BusinessType.UPDATE)
    @PutMapping("/backCheckTaskOrder")
    public AjaxResult backCheckTaskOrder(@RequestBody Map<String, String> data){
        return toAjax(appTaskOrderService.backCheckTaskOrder(data));
    }
}
